<template>
  <div id="app">
    <el-row :gutter="20">
      <el-col :span="8">
        <el-date-picker v-model="dateVal" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
          value-format="yyyy-MM-dd" @change="chooseDate">
        </el-date-picker>
      </el-col>
      <el-col :span="6">
        <el-button type="primary" @click="getData">查询</el-button>
        <el-button @click="downLoad">导出</el-button>
      </el-col>
    </el-row>
    <el-row style="margin-top: 20px;">
      <el-col :span="24">
        <el-table :data="list" border style="width: 100%">
          <el-table-column prop="date" label="日期">
          </el-table-column>
          <el-table-column prop="1" label="默认抽奖机会">
          </el-table-column>
          <el-table-column prop="2" label="视频抽奖机会">
          </el-table-column>
          <el-table-column prop="3" label="做任务抽奖机会">
          </el-table-column>
          <el-table-column prop="4" label="发任务抽奖机会">
          </el-table-column>
          <el-table-column prop="11" label="再来一次">
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  import fetch from '@/api/axios';
  export default {
    data() {
      return {
        list: [],
        dateVal: '',
        start_time: '',
        end_time: '',
        page: 1,
      };
    },
    methods: {
      getData() {
        fetch.get('/api/console/lotterydraw/statistical_chance', {
          start_time: this.start_time,
          end_time: this.end_time,
          page: this.page,
        }).then((res) => {
          let data = res.data
          this.list = data.data
        })
      },
      chooseDate(date) {
        this.start_time = date[0]
        this.end_time = date[1] + ' x'
      },
      downLoad() {
        fetch.get('/api/console/lotterydraw/out_excel', {
            m: 'statistical_chance',
            start_time: this.start_time,
            end_time: this.end_time,
          }, {
            responseType: 'blob'
          }).then(res => {
            console.log("response: ", res);
            // new Blob([data])用来创建URL的file对象或者blob对象
            let url = window.URL.createObjectURL(new Blob([res.data]));
            // 生成一个a标签
            let link = document.createElement("a");
            link.style.display = "none";
            link.href = url;
            // 生成时间戳
            let timestamp = new Date().getTime();
            link.download = timestamp + ".xlsx";
            document.body.appendChild(link);
            link.click();
          })
          .catch(error => {
            console.log("response: ", error);
          });
      }
    },
    mounted() {
      this.getData();
    },
    watch: {
      classList(newName, oldName) {
        let _this = this;
        for (var i in _this.classList) {
          if (_this.classList[i].name == _this.className) {
            _this.classIndex = i;
          }
        }
      }
    }
  };
</script>
<style lang="scss" scoped>
  .helpUl {
    li {
      float: left;
      border-radius: 3px;
      margin-right: 20px;
      margin-bottom: 20px;
      padding: 0 19px;
      line-height: 32px;
      height: 34px;
      font-size: 15px;
      border: 1px solid #eee;
      color: #666;
      cursor: pointer;

      &.active {
        background: linear-gradient(to right, #6eb5ff, #409efe);
        color: #fff;
        border: 1px solid #409efe;
      }
    }

  }

  .hadlebox {
    float: right;

    .handleBtn {
      float: left;
      margin-left: 35px;
      font-size: 15px;
      line-height: 30px;
      color: #333;
      cursor: pointer;
    }
  }

  .con_list {
    li {
      text-align: left;
      height: 42px;
      line-height: 40px;
      border-bottom: 1px solid #f9f9f9;
      font-size: 15px;
      color: #666;
      margin-bottom: 10px;
      cursor: pointer;

      i {
        vertical-align: middle;
        display: inline-block;
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: #333;
        margin-right: 10px;
        margin-top: -2px;
      }
    }
  }

  .editor {
    width: 100%;
    height: 250px;
    overflow: hidden;

    .w-e-text-container {
      height: 200px;
    }
  }
</style>
